package com.nononsenseapps.feeder.processor.interceptor

import com.nononsenseapps.feeder.db.entity.FeedItem
import com.nononsenseapps.feeder.db.room.ID_UNSET
import com.nononsenseapps.feeder.processor.Interceptor
import com.nononsenseapps.feeder.util.NlpUtils
import com.nononsenseapps.feeder.util.NlpUtils.CHINA_HK
import java.util.*

class LanguageTranInterceptor : Interceptor {

    override fun intercept(chain: Interceptor.Chain): FeedItem {
        val feed = chain.getFeed()
        val feedItem = chain.getFeedItem()
        val context = chain.getProcessContext()

        if(feed.id == ID_UNSET) {
            feedItem.description =
                NlpUtils.tranLanguage(CHINA_HK, Locale.getDefault(), feedItem.description)
            feedItem.title =
                NlpUtils.tranLanguage(CHINA_HK, Locale.getDefault(), feedItem.title)
            context.modifyFlag = true
        }
        return chain.proceed(feed, feedItem)
    }
}